package com.wxmblog.photo.controller;

//import org.apache.shiro.authz.annotation.RequiresPermissions;

import com.wxmblog.base.common.annotation.AuthIgnore;
import com.wxmblog.base.common.constant.ParamTypeConstants;
import com.wxmblog.base.common.utils.PageResult;
import com.wxmblog.base.common.utils.TokenUtils;
import com.wxmblog.base.common.web.domain.R;
import com.wxmblog.photo.common.rest.request.product.front.ProductIndexRequest;
import com.wxmblog.photo.common.rest.response.product.front.ProductIndexResponse;
import com.wxmblog.photo.service.ProductService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 备注
 *
 * @author wanglei
 * @email 378526425@qq.com
 * @date 2023-06-20 15:24:40
 */
@RestController
@RequestMapping("photo/product")
@Api(tags = "前台-产品管理")
public class ProductController {

    @Autowired
    private ProductService productService;


    @ApiImplicitParams({
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageIndex", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageSize", value = "数量", defaultValue = "10")
    })
    @ApiOperation("产品列表")
    @ApiOperationSort(value = 1)
    @GetMapping("/page")
    @AuthIgnore
    public R<PageResult<ProductIndexResponse>> page(ProductIndexRequest request,
                                                    @RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return R.ok(productService.frontPage(request, pageIndex, pageSize));
    }


    @ApiOperation("产品推荐")
    @ApiOperationSort(value = 2)
    @GetMapping("/recommend")
    @AuthIgnore
    public R<List<ProductIndexResponse>> recommend(ProductIndexRequest request) {
        return R.ok(productService.recommend(request));
    }

    @ApiOperation("产品收藏/取消收藏")
    @ApiOperationSort(value = 3)
    @GetMapping("/collect/{id}/{result}")
    public R<Void> collect(@PathVariable Integer id, @PathVariable Boolean result) {
        productService.collect(id, result);
        return R.ok();
    }

    @ApiOperation("产品浏览记录增加")
    @ApiOperationSort(value = 4)
    @GetMapping("/view/{id}")
    public R<Void> view(@PathVariable Integer id) {
        productService.view(id, TokenUtils.getOwnerId());
        return R.ok();
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageIndex", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageSize", value = "数量", defaultValue = "10")
    })
    @ApiOperation("我的下载记录")
    @ApiOperationSort(value = 5)
    @GetMapping("/download/record")
    public R<PageResult<ProductIndexResponse>> downloadRecord(
            @RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return R.ok(productService.downloadRecord(pageIndex, pageSize));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageIndex", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageSize", value = "数量", defaultValue = "10")
    })
    @ApiOperation("我的收藏记录")
    @ApiOperationSort(value = 6)
    @GetMapping("/collect/record")
    public R<PageResult<ProductIndexResponse>> collectRecord(
            @RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return R.ok(productService.collectRecord(pageIndex, pageSize));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageIndex", value = "页码", defaultValue = "1"),
            @ApiImplicitParam(paramType = ParamTypeConstants.requestParam, name = "pageSize", value = "数量", defaultValue = "10")
    })
    @ApiOperation("我的浏览记录")
    @ApiOperationSort(value = 7)
    @GetMapping("/view/record")
    public R<PageResult<ProductIndexResponse>> viewRecord(
            @RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return R.ok(productService.viewRecord(pageIndex, pageSize));
    }
}
